#include<bits/stdc++.h>
using namespace std;
string s[110],op[110];
bool check(string x,string y)
{
	int len=x.size();
	for(int i=1;i<=len;i++)
	{
		if(x[i]!=y[i])return false;
	}
	return true;
}
int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>op[i]>>s[i];
		if(op[i]=="Server")cout<<"OK"<<endl;
	}
	for(int i=1;i<=n;i++)
	{
		bool flag=false;
		if(op[i]=="Server")continue;
		else if(op[i]=="Client")
		{
			for(int j=1;j<=n;j++)
			{
				if(check(s[i],s[j])==true&&op[j]=="Server")
				{
					cout<<j<<endl;
					flag=true;
					break;
				}
				
			}
			if(flag==false)cout<<"FAIL"<<endl;
		}
	}
	return 0;
}
